// 自定义指令
import defaultImg from "@/assets/images/200.png";
const laze = {
  // el 指令所在的元素
  // binding.value 获取指令的值
  mounted(el, binding) {
    const observer = new IntersectionObserver(([{ isIntersecting }]) => {
      if (isIntersecting) {
        observer.unobserve(el);
        // 加载图片
        el.src = binding.value;
        // 监听图片加载失败的情况
        el.onerror = () => {
          el.src = defaultImg;
        };
      }
    });
    observer.observe(el);
  },
};

export default laze;
